/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Pe.edu.unmsm.SIASS.DAOImpl;

import Pe.edu.unmsm.SIASS.DAO.AlumnoDAO;
import Pe.edu.unmsm.SIASS.Dominio.Alumno;
import Pe.edu.unmsm.SIASS.Dominio.HorarioGrupo;
import Util.HibernateUtil;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Fabrica
 */
public class AlumnoDAOImpl implements AlumnoDAO, Serializable{

    @Override
    public List<Alumno> listarAlumnosXGrupo(int idGrupo) {
        List<Alumno> lista = new ArrayList<Alumno>();
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            Query query = session.createQuery("select distinct a from Alumno a, AlumnoGrupo ag, Grupo g where ag.alumno=a"
                    + " and ag.grupo=g and g.idGrupo="+idGrupo);
            lista = (List<Alumno>) query.list();
            for (Alumno alumno : lista) {
                Hibernate.initialize(alumno.getPersona());
            }
            session.beginTransaction().commit();
            session.close();
        } catch (Exception e) {
            session.beginTransaction().rollback();
            e.printStackTrace();
        }
        return lista;
    }
    
    
    
}
